package com.gujiangbo.reference;

import java.lang.ref.SoftReference;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/3/12 09:41
 * @Version: 1.0
 * @Description: 软引用 只有在内存不足的时候才会被回收
 */
public class SoftReferenceDemo {

    public static void main(String[] args) {

        Object o1 = new Object();
        SoftReference<Object> softReference = new SoftReference<>(o1);

        System.out.println(o1);
        System.out.println(softReference.get());

        o1 = null;
        System.gc();

        System.out.println("======");

        System.out.println(o1);
        System.out.println(softReference.get());

    }
}
